package com.yuanduo_app.ui.common.view;

import android.app.Activity;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;
import com.just.agentweb.WebViewClient;
import com.xujl.fastlib.base.BaseView;
import com.xujl.fastlib.base.IControl;

import com.yuanduo_app.databinding.ActivityCommonWebBinding;
import com.yuanduo_app.widget.CoolIndicatorLayout;


/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class CommonWebActivityView extends BaseView<ActivityCommonWebBinding> {
    private AgentWeb mAgentWeb;

    @Override
    public void init (IControl control) {

    }

    public void initWeb (Activity activity, String url) {
        CoolIndicatorLayout coolIndicator = new CoolIndicatorLayout(activity);
        mAgentWeb = AgentWeb.with(activity)
                .setAgentWebParent(mBind.llWeb, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT))
                .setCustomIndicator(coolIndicator)
                .setWebChromeClient(new WebChromeClient() {
                    @Override
                    public void onReceivedTitle (WebView view, String webTitle) {
                        super.onReceivedTitle(view, webTitle);
//                        if (StringUtils.isEmpty(title) ) {
//                            binding.includeToolbar.titleBar.setTitle(webTitle);
//                        }
                    }
                })
                .setWebViewClient(new WebViewClient() {

//                    @Override
//                    public boolean shouldOverrideUrlLoading (WebView view, String url) {
//                        if (mInterceptorSparseArray == null) {
//                            return super.shouldOverrideUrlLoading(view, url);
//                        }
//                        return interceptorRun(view, url, this);
//                    }

//                    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//                    @Override
//                    public boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) {
//                        if (mInterceptorSparseArray == null) {
//                            return super.shouldOverrideUrlLoading(view, request);
//                        }
//
//                        return interceptorRun(view, request, this);
//                    }
//
//                    @Override
//                    public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
////                        super.onReceivedSslError(view, handler, error);
//
//                        handler.proceed();
//                    }
                })


                .createAgentWeb()
                .ready()
                .go(url);

    }
}
